package cn.com.pxto.commons.pagesupport;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import cn.com.pxto.commons.httputil.ParamUtil;
/**
 * 
 * Copyright (C) 2006 Bejing iActive Tec Co.,Ltd File: PageUtils.java
 * 
 * file description
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * @author Lu Guo Xiang 2006-7-31
 */
public class PageUtils {
	/**
	 * ȡ��HttpServletRequest�еķ�ҳ��Ϣ�������PageInfo����
	 */
	public static PageInfo getPageInfo(HttpServletRequest request){
		int pageNo = ParamUtil.getIntParams(request, "pageNo", 1);
		int pageSize = ParamUtil.getIntParams(request, "pagesize", PageInfoFactory.DefaultPageSize);
		return PageInfoFactory.getPageInfo(pageSize,pageNo);
	}
	/**
	 * ��HttpServletRequest�����÷�ҳ��Ϣ
	 */
	public static void setPageInfoAttr(HttpServletRequest request, PageInfo pageInfo) {
		request.setAttribute("pageInfo", pageInfo);
	}
	/**
	 * ȡ��list���ڵ�ǰҳ�����б?
	 */
	public static List getListInPage(PageInfo pageInfo,List list){
		int end = pageInfo.getBeginResult() + pageInfo.getPageSize();
		if (end > list.size())
			end = list.size();
		list = list.subList(pageInfo.getBeginResult(), end);	
		return list;
	}


}
